import java.util.HashMap;
import java.util.ArrayList;


public class Solution {

    public static HashMap<String,String> longToShort = new HashMap<String,String>();
    public static ArrayList<String> longList = new ArrayList<String>();
    public static int number = 0;

    public static void main(String[] args){
        Solution s = new Solution();
        String url1 = "http://www.baidu.com";
        String url2 = "http://www.google.com";
        String tiny1 = s.encode(url1);
        String tiny2 = s.encode(url2);
        System.out.println(tiny1);
        System.out.println(tiny2);
        System.out.println(s.encode(url1));

        System.out.println(s.decode(tiny1));
        System.out.println(s.decode(tiny2));

    }
    
    // Encodes a URL to a shortened URL.
    public String encode(String longUrl) {
        if(longToShort.containsKey(longUrl)){
            return  longToShort.get(longUrl);
        }
        String prefix = "http://vtamins.com/";
        String shortUrl= prefix+number;
        number++;
        longToShort.put(longUrl,shortUrl);
        longList.add(longUrl);
        return shortUrl;
    }
    
    // Decodes a shortened URL to its original URL.
    public String decode(String shortUrl) {
        String[] strTmp = shortUrl.split("/");
        int index = Integer.parseInt(strTmp[strTmp.length-1]);
        return longList.get(index);
        
    }
    }
    
    // Your Codec object will be instantiated and called as such:
    // Codec codec = new Codec();
    // codec.decode(codec.encode(url));